package com.qiyou.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qiyou.dao.IScenicSpotDao;
import com.qiyou.dao.factory.DaoFactory;
import com.qiyou.entity.ScenicSpot;

/**
 * 加载活动列表
 */
@WebServlet(name = "AttestationList", urlPatterns = { "/AttestationList" })
public class AttestationListServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        String userID = request.getParameter("userID");

        IScenicSpotDao spotDao = DaoFactory.getScenicSpotDao();
        List<ScenicSpot> spots = null;

        try {
            if ((null != userID) && (!userID.isEmpty())) {
                String sql = "where tb_scenic_spots.scsID in (select a.scsID from tb_scenic_spots a,tb_place_attestation where a.scsID=tb_place_attestation.sceID and tb_place_attestation.userID='"
                        + userID
                        + "' order by tb_place_attestation.attDate desc) limit 25";
                spots = spotDao.getScenicSpots(new Object[] { sql });

                if (null != spots) {
                    request.setAttribute("spots", spots);
                    request.getRequestDispatcher("approve.jsp").forward(
                            request, response);
                }
            } else {
                response.getWriter()
                        .print("<script  language='javascript'>alert('请求的用户信息有误');history.go(-1);</script>");
            }
        } catch (Exception e) {
            response.getWriter()
                    .print("<script  language='javascript'>alert('请求的用户信息有误');history.go(-1);</script>");
        }
    }

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
    }

}
